package com.ildan.app.util;

import java.util.ArrayList;

import com.ildan.app.toilet.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SearchCustomAdapter extends BaseAdapter {

	Context mContext;
	ArrayList<AddrData> mArrayList;
	String[] mList;
	LayoutInflater mInflater;
	int mLayout = 0;
	AddrData resultData;
	Double[] lat, lng;

	public SearchCustomAdapter(){}
	
	public SearchCustomAdapter(Context context, ArrayList<AddrData> list, int layout){
		mContext = context;
		mArrayList = list;
		mLayout = layout;
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		lat = new Double[list.size()];
		lng = new Double[list.size()];
	}
	
	@Override
	public int getCount() {
		return mArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		resultData = (AddrData) getItem(position);
		
		lat[position] = resultData.getLat();
		lng[position] = resultData.getLng();
		
		if(convertView == null) convertView = mInflater.inflate(mLayout, parent, false);
		
		TextView title = (TextView)convertView.findViewById(R.id.titleList_txt);
		TextView addr = (TextView)convertView.findViewById(R.id.addrList_txt);
		
		title.setText("\""+resultData.getTitle()+"\" \n");
		addr.setText(resultData.getAddr().replace("[", "").replace("]", "").replace("\"", "")
					.replace(mContext.getResources().getString(R.string.korea),""));
		return convertView;
	}

	public Double getLat(int position) {
		return lat[position];
	}

	public Double getLng(int position) {
		return lng[position];
	}

}
